<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<CreatePayload>" %>
<%@ Import Namespace="ActivateYourGlutes.Payloads.Goal"%>
<%@ Import Namespace="ActivateYourGlutes.Model.Contracts"%>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Create a Goal
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<%
    var localeSettings = (UserLocaleSettings) ViewData["localeSettings"];
    var dateFormat = localeSettings.DateFormat;
    var jqueryDateFormat = localeSettings.JQueryDateFormat;
    var targetDate = ViewData.Model.Goal.TargetDate == null
                         ? ""
                         : ((DateTime) ViewData.Model.Goal.TargetDate).ToString(dateFormat);
    var measurementTypes = ViewData.Model.MeasurementTypes;
    var selectList = ViewData.Model.IncreaseDecrease;
%>
<script type="text/javascript">
  $(document).ready(function() {
    $("#TargetDate").datepicker({ defaultDate: 0, dateFormat: '<%= jqueryDateFormat %>' });
    $("#entryForm").validate({
        rules: {
            LocalisedValue: {
                min: 1,
                required: true
            },
            TargetDate: {
                required: false
            }
        }
    });
  });
</script>
    <div id="subheader">
        <h2>Add Goal</h2>        
        <div>
            <%= Html.ActionLink("Back to Goals", MVC.Goal.Index()) %>
        </div>
    </div>
    <%= Html.ValidationSummary() %>
    <% using (Html.BeginForm(null, null, null, FormMethod.Post, new { id="entryForm" }))
       { %>
    <%= Html.AntiForgeryToken() %>
    <fieldset class="inline">
        <table>
            <tr>
                <td>Type</td>
                <td>
<%
           bool isChecked = true;
        foreach (var measurementType in measurementTypes)
        {
%>
            <%= Html.RadioButton("MeasurementType", measurementType.MeasurementTypeId, isChecked) %>
            <label style="padding-right: 1em"><%=  measurementType.Description %></label>
<%
            isChecked = false;
        }
%>
                </td>
            </tr>
            <tr>
                <td>Target</td>
                <td>
                    <%= Html.DropDownList("DecreaseTo", selectList)%>
                    &nbsp;
                    <%= Html.TextBox("LocalisedValue", ViewData.Model.Goal.LocalisedValue)%>
                </td>
            </tr>
            <tr>
                <td><label for="TargetDate">By</label></td>
                <td><%=Html.TextBox("TargetDate", Html.Encode(targetDate))%></td>
            </tr>
        </table>
        <input id="save" name="save" type="submit" value="Save Goal" />
    </fieldset>
    <% } %>
</asp:Content>
